﻿@inject NavigationManager NavigationManager;
@inject ServiceStackStateProvider AuthStateProvider;

<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
    <Found Context="routeData">
        <AuthorizeRouteView RouteData="@routeData"
                            DefaultLayout="@NavigationManager.GetPageLayout(routeData)">
            <NotAuthorized>
                <h1 class="mb-4 text-2xl font-semibold text-gray-900 dark:text-gray-100">
                    Sorry
                </h1>
                <p>You're not authorized to reach this page.</p>
                <p>
                    Please
                    <NavLink class="underline hover:text-green-600" @onclick=@login href="javascript:void">login</NavLink>
                    as a different user.
                </p>
            </NotAuthorized>

            <Authorizing>
                <p class="text-gray-400 absolute -mt-4 mr-4 right-0">Authenticating...</p>
                <RouteView RouteData="@routeData" DefaultLayout="@NavigationManager.GetPageLayout(routeData)" />
            </Authorizing>

        </AuthorizeRouteView>
    </Found>
    <NotFound>
        <LayoutView Layout="@typeof(MainLayout)">
            <div class="min-h-full bg-white px-4 py-16 sm:px-6 sm:py-24 md:grid md:place-items-center lg:px-8">
                <div class="mx-auto max-w-max">
                    <main class="sm:flex">
                        <p class="text-4xl font-bold tracking-tight text-indigo-600 sm:text-5xl">404</p>
                        <div class="sm:ml-6">
                            <div class="sm:border-l sm:border-gray-200 sm:pl-6">
                                <h1 class="text-4xl font-bold tracking-tight text-gray-900 sm:text-5xl">Page not found</h1>
                                <p class="mt-2 text-base text-gray-500">Please check the URL in the address bar and try again.</p>
                            </div>
                            <div class="mt-10 flex space-x-3 sm:border-l sm:border-transparent sm:pl-6">
                                <PrimaryButton href="/">Go back home</PrimaryButton>
                                <SecondaryButton href="https://docs.servicestack.net/#community-support">Contact support</SecondaryButton>
                            </div>
                        </div>
                    </main>
                </div>
            </div>
        </LayoutView>
    </NotFound>
</Router>
</CascadingAuthenticationState>

@code {
    async Task login()
    {
        await AuthStateProvider.LogoutIfAuthenticatedAsync(redirectTo: NavigationManager.GetLoginUrl());
    }
}
